<!-- src/components/HomePage.vue -->
<template>
  <div class="app-container">
    <div class="navbar">
      <button
        @click="setComponent('CarTop')"
        :class="{ active: currentComponent === 'CarTop' }"
      >
        进口数据详情
      </button>
      <button
        @click="setComponent('CarCount')"
        :class="{ active: currentComponent === 'CarCount' }"
      >
        出口数据详情
      </button>
      <button
        @click="setComponent('JingJi')"
        :class="{ active: currentComponent === 'JingJi' }"
      >
        进出口形势
      </button>
      <button
        @click="setComponent('carnew')"
        :class="{ active: currentComponent === 'carnew' }"
      >
        数据分析
      </button>
      <button
        @click="setComponent('MapPage')"
        :class="{ active: currentComponent === 'MapPage' }"
      >
        主要地点
      </button>
    </div>
    <div class="content">
      <component :is="components[currentComponent]"></component>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import CarTop from "@/components/CarTop.vue";
import CarCount from "@/components/CarCount.vue";
import JingJi from "@/components/JingJi.vue";
import MapPage from "@/components/MapPage.vue";
import carnew from "@/components/carnew.vue";
// npx prettier --write .
const components = {
  CarTop,
  CarCount,
  JingJi,
  MapPage,
  carnew,
};

const currentComponent = ref(
  localStorage.getItem("currentComponent") || "CarTop"
);

const setComponent = (componentName) => {
  currentComponent.value = componentName;
  localStorage.setItem("currentComponent", componentName);
};

onMounted(() => {
  currentComponent.value = localStorage.getItem("currentComponent") || "CarTop";
});
</script>

<style scoped>
.app-container {
  font-family: Arial, sans-serif;
  background-color: #121212;
  color: #ffffff;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  display: flex;
  justify-content: space-around;
  background-color: #1e1e1e;
  padding: 10px;
  border-bottom: 2px solid #007bff;
}

.navbar button {
  padding: 10px 20px;
  cursor: pointer;
  background-color: transparent;
  border: none;
  color: #ffffff;
  font-size: 16px;
  transition: color 0.3s ease;
}

.navbar button:hover {
  color: #007bff;
}

.navbar button.active {
  color: #007bff;
  border-bottom: 2px solid #007bff;
  animation: pulse 1s infinite;
  font-size: 20px;
  font-weight: 600;
  -webkit-animation: pulse 1s infinite;
  -moz-animation: pulse 1s infinite;
  -o-animation: pulse 1s infinite;
}

.content {
  flex: 1;
  padding: 20px;
  background-color: #1e1e1e;
  border: 1px solid #007bff;
  border-radius: 5px;
  margin: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  overflow-y: auto;
}

@keyframes pulse {
  0% {
    border-bottom-color: #007bff;
  }
  50% {
    border-bottom-color: #0056b3;
  }
  100% {
    border-bottom-color: #007bff;
  }
}
</style>
